[Solved] static method charCount() that takes a string and a file name as...

您所在的位置:网站首页 java static [Solved] static method charCount() that takes a string and a file name as...

[Solved] static method charCount() that takes a string and a file name as...

#[Solved] static method charCount() that takes a string and a file name as... | 来源: 网络整理| 查看: 265

static method charCount() that takes a string and a file name as arguments and throws an IOException. The method prints out a table into the file: for each character that occurs in the string, the table contains the character and its frequency of occurrence. Assume that the string contains only ASCII characters. Any IOExceptions that arise are not caught but being propagated into the calling code.

Sample string: Alex A.

Output:

聽聽1. 1A 2e 1l 1x 1

Suggested approach: Create an array of short integers, where each element is holding frequency of occurrence of a character with specific character code. The element of the array is associated with the character ASCII code via element index, for example element with index 65 is holding the frequency of character A. Use the array as storage for the frequencies of the characters, incrementing the corresponding frequency each time you encounter the character in the given string.

Requirement: The method must be efficient - it must complete the task with only ONE pass through the string.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3